<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<script type="text/javascript">
	function studentDelete(studentId) {
		if(confirm("您确定要删除这个学生吗？")) {
			window.location="user?action=delete&studentId="+studentId;
		}
	}
$(document).ready(function(){
	$("ul li:eq(1)").addClass("active");
	$('.dataTable').dataTable( {
        "oLanguage": {
            "sProcessing":   "处理中...",
            "sLengthMenu":   "_MENU_ 记录/页",
            "sZeroRecords":  "没有匹配的记录",
            "sInfo":         "显示第 _START_ 至 _END_ 项记录，共 _TOTAL_ 项",
            "sInfoEmpty":    "显示第 0 至 0 项记录，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项记录过滤)",
            "sInfoPostFix":  "",
            "sSearch":       "查找（所有信息）:",
            "sUrl":          ""
        },

        "bPaginate": false ,//该参数为是否显示分页
		"bLengthChange": false, //改变每页显示数据数量
        "bStateSave": true,
		"bFilter": true, //过滤功能
		"aoColumns": [
			null,
			null,
			null,
			null,
			null,
			null,
			null,
            {"asSorting":[]},
			{"asSorting": [ ] }
		]
	});
});

window.onload = function(){ 
	$("#DataTables_Table_0_wrapper .row-fluid").remove();
};
</script>
<style type="text/css">
	.span6 {
		width:0px;
		height: 0px;
		padding-top: 0px;
		padding-bottom: 0px;
		margin-top: 0px;
		margin-bottom: 0px;
	}

</style>
<div class="data_list">
		<div class="data_list_title">
			学生管理
		</div>
		<form name="myForm" class="form-search" method="post" action="user?action=search" style="padding-bottom: 0px">
				<button class="btn btn-success" type="button" style="margin-right: 50px;" onclick="javascript:window.location='user?action=preSave'">添加</button>
				<span class="data_search">
					<select id="buildId" name="buildId" style="width: 110px;">
					<option value="">全部宿舍楼</option>
					<c:forEach var="build" items="${buildList }">
						<option value="${build.id }"}>${build.name }</option>
					</c:forEach>
					</select>
					<select id="searchType" name="searchType" style="width: 80px;">
					<option value="name">姓名</option>
					<option value="num" ${searchType eq "num"?'selected':'' }>学号</option>
					<option value="roomNum" ${searchType eq "roomNum"?'selected':'' }>寝室</option>
					</select>
					&nbsp;<input id="searchText" name="searchText" type="text"  style="width:120px;height: 30px;" class="input-medium search-query" value="${searchText}">
					&nbsp;<button type="submit" class="btn btn-info" onkeydown="if(event.keyCode==13) myForm.submit()">搜索</button>
				</span>
		</form>
		<div>
			<table class="table table-striped table-bordered table-hover dataTable" >
				<thead>
					<tr>
					<th>登录名</th>
					<th>姓名</th>
					<th>性别</th>
					<th>学号</th>
					<th>宿舍楼</th>
					<th>寝室</th>
					<th>电话</th>
					<th>角色类型</th>
					<th>操作</th>
				</tr>
				</thead>
				<tbody>
				<c:forEach  varStatus="i" var="student" items="${userList}">
					<tr>
						<td>${student.userName }</td>
						<td>${student.name }</td>
						<td>${student.sex }</td>
						<td>${student.num }</td>
						<td>${student.buildName==null?"无":student.buildName }</td>
						<td>${student.roomNum ==null?"无":student.roomNum }</td>
						<td>${student.tel }</td>
						<td>${student.userType == 1?"系统管理员":"学生"}</td>
						<c:choose>
							<c:when test="${student.userType != 1}">
								<td>
									<button class="btn btn-mini btn-info" type="button" onclick="javascript:window.location='user?action=preSave&studentId=${student.id}'">修改</button>&nbsp;
									<button class="btn btn-mini btn-danger" type="button" onclick="studentDelete(${student.id })">删除</button>
								</td>
							</c:when>
							<c:otherwise>
								<td></td>
							</c:otherwise>
						</c:choose>
					</tr>
				</c:forEach>
				</tbody>
			</table>
		</div>
		<div align="center"><span style="color:red;">${error }</span></div>
		<div class="pagination pagination-centered">
			<ul>
				${pageCode }
			</ul>
		</div>
</div>